/**
 *
 *  License: http://www.apache.org/licenses/LICENSE-2.0
 *  Home page: https://gitee.com/linlurui/service-abc
 *  Note: to build on java, include the jdk1.8+ compiler symbol (and yes,
 *  I know the difference between language and runtime versions; this is a compromise).
 * @author linlurui
 * @Date Date: 2019-02-10
 */


package abc.resolver;


import abc.utils.ClassUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.MethodParameter;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.support.WebDataBinderFactory;
import org.springframework.web.context.request.NativeWebRequest;
import org.springframework.web.method.support.HandlerMethodArgumentResolver;
import org.springframework.web.method.support.ModelAndViewContainer;
import java.lang.reflect.Type;
import java.util.Map;


@Configuration
public class RequestBodyResolver implements HandlerMethodArgumentResolver {

    private static final Logger log = LoggerFactory.getLogger( RequestBodyResolver.class );

    @Override
    public boolean supportsParameter(MethodParameter parameter) {
        return parameter.hasParameterAnnotation(RequestBody.class);
    }

    @Override
    public Object resolveArgument(MethodParameter parameter, ModelAndViewContainer mavContainer,
                                  NativeWebRequest webRequest, WebDataBinderFactory binderFactory) throws Exception {
        try {
            final Type type = parameter.getGenericParameterType();

            Class clazz = null;

            if (type.getTypeName().indexOf("List<") > 0) {


            } else {

                clazz = ClassUtil.getClassByType(type);
            }
        }
        catch (Exception e) {
            log.error("RequestBody参数化失败=====>>> ", e);
        }

        return parameter;
    }
}
